import utils.TreeNode;

/**
 * @author ZCR
 * @create 2025/9/4 22:27
 */
public class Solution110 {
    boolean isBalance = true;
    public boolean isBalanced(TreeNode root) {
        if (root == null) {
            return true;
        }
        maxDepth(root);
        return isBalance;

    }
    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        int left = maxDepth(root.left);
        int right = maxDepth(root.right);
        if(Math.abs(left - right) > 1) {
            isBalance = false;
        }
        return left > right ? left + 1 : right + 1;

    }
}
